﻿# -*- coding: utf-8 -*-

from PyQt5 import QtCore,QtGui
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QDialog, QHBoxLayout, QFrame, QVBoxLayout, QLabel, QSpacerItem, QSizePolicy, QApplication



from libs.mybuttons import ImageButton

_translate = QApplication.translate


class loading(QDialog):
    loadingclosed = pyqtSignal()
    def __init__(self, parent=None):
        super(loading, self).__init__(parent)
        self.setObjectName("loading")
        self.resize(321, 209)
        self.setStyleSheet("background: #234775;")
        self.setWindowModality(QtCore.Qt.ApplicationModal)
        self.setWindowFlags(QtCore.Qt.CustomizeWindowHint | QtCore.Qt.FramelessWindowHint | QtCore.Qt.Dialog)    
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setContentsMargins(5, 0, 5, 10)
        self.verticalLayout.setObjectName("verticalLayout")
        self.frame = QFrame(self)
        self.frame.setMaximumSize(QtCore.QSize(16777215, 30))
        self.frame.setFrameShape(QFrame.StyledPanel)
        self.frame.setFrameShadow(QFrame.Raised)
        self.frame.setObjectName("frame")
        self.horizontalLayout = QHBoxLayout(self.frame)
        self.horizontalLayout.setSpacing(6)
        #self.horizontalLayout.setMargin(0)
        self.horizontalLayout.setObjectName("horizontalLayout")
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.horizontalLayout.addItem(spacerItem)
        self.min = ImageButton(parent=self.frame)
        self.min.setMaximumSize(QtCore.QSize(30, 16777215))
        self.min.setObjectName("min")
        self.min.loadPixmap(":/mini_white.png", has4Status=True)
        self.horizontalLayout.addWidget(self.min)
        self.closeBt = ImageButton(parent=self.frame)
        self.closeBt.setMaximumSize(QtCore.QSize(30, 16777215))
        self.closeBt.setObjectName("closeBt")
        self.closeBt.loadPixmap(":/close_white.png",has4Status=True)
        self.horizontalLayout.addWidget(self.closeBt)
        self.verticalLayout.addWidget(self.frame)
        self.label = QLabel(self)
        self.label.setMinimumSize(QtCore.QSize(0, 150))
        self.label.setMaximumSize(QtCore.QSize(16777215, 16777215))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(25)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setStyleSheet("color: white;")
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        spacerItem1 = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem1)
        self.label_2 = QLabel(self)
        self.label_2.setMaximumSize(QtCore.QSize(16777215, 25))
        self.label_3 = QLabel(self)
        self.label_3.setMaximumSize(QtCore.QSize(16777215, 25))
        font = QtGui.QFont("verdana", 7)
        self.label_2.setFont(font)
        self.label_2.setStyleSheet("color: white;")
        self.label_2.setObjectName("label_2")
        self.label_2.setAlignment(QtCore.Qt.AlignHCenter)
        self.label_3.setFont(font)
        self.label_3.setStyleSheet("color: white;")
        self.label_3.setObjectName("label_3")
        self.label_3.setAlignment(QtCore.Qt.AlignHCenter)
        self.verticalLayout.addWidget(self.label_3)
        self.verticalLayout.addWidget(self.label_2)
        self.label_3.setText("--/--")
        self.movie = QtGui.QMovie(':/loading.gif', QtCore.QByteArray())
        self.movie.setCacheMode(QtGui.QMovie.CacheAll)
        self.movie.setSpeed(100)
        self.label_2.setMovie(self.movie)

        self.movie.start()
        self.min.clicked.connect(self.showMinimized)
        self.closeBt.clicked.connect( self.closed)
        if self.parent():
            #self.parent().sig_loadCompleted.connect(self.closeWhenCompleted)
            #self.parent().sig_progress.connect(self.showProgress)
            pass
        self.retranslateUi()
        #QtCore.QMetaObject.connectSlotsByName(self)
        
    def retranslateUi(self):
        self.setWindowTitle(_translate("Dialog", "Dialog", None))
        self.min.setText(_translate("Dialog", "PushButton", None))
        self.min.setToolTip("Minimize")
        self.closeBt.setText(_translate("Dialog", "PushButton", None))
        self.closeBt.setToolTip("Close")
        self.label.setText(_translate("Dialog", "{{cookiecutter.application_name}}", None))
        #self.label.setPixmap(QtGui.QPixmap(":/logostring.png"))


    def showProgress(self, s):
        self.label_3.setText(s)
        
    def closed(self):
        self.loadingclosed.emit()
        self.close()
        
    def closeWhenCompleted(self):
        self.parent().show()
        self.parent().trayIcon.show()
        self.close()

if __name__ == '__main__':
    import cookiecutter_pyqt5.resources_rc
    import sys
    app = QApplication(sys.argv)
    dialog = loading()
    dialog.show()
    sys.exit(app.exec_())